﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace SDFL.Core
{
    public class PerfCounters
    {
        private static PerfCounters _perfCounters;
        private static object lockHelper = new object();

        private List<PerformanceCounter> counterList = new List<PerformanceCounter>();
        public readonly PerformanceCounter cpuCounter = null;
        public readonly PerformanceCounter ramCounter = null;
        public readonly PerformanceCounter pageCounter = null;
        public readonly PerformanceCounter[] nicCounters = null;

        private PerfCounters(string machineName)
        {
            cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", machineName);
            ramCounter = new PerformanceCounter("Memory", "% Committed Bytes In Use", String.Empty, machineName);
            pageCounter = new PerformanceCounter("Paging File", "% Usage", "_Total", machineName);
                                 
            nicCounters = SDFL.Remoting.Helper.GetNICCounters(machineName);
        }

        public static PerfCounters GetPerfCountersInstance(string machineName)
        {
            if (_perfCounters == null)
            {
                lock (lockHelper)
                {
                    if (_perfCounters == null)
                    {
                        _perfCounters = new PerfCounters(machineName);
                    }
                }
            }
            return _perfCounters;
        }
    }
}
